package com.kaibo.roomdemo.activity

import android.os.Build
import android.support.v7.app.AppCompatActivity
import android.os.Bundle
import android.support.annotation.RequiresApi
import android.transition.*
import com.kaibo.roomdemo.R
import kotlinx.android.synthetic.main.activity_animation_demo2.*

class AnimationDemo2Activity : AppCompatActivity() {

    @RequiresApi(Build.VERSION_CODES.M)
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_animation_demo2)

        val scene1 = Scene.getSceneForLayout(scene_root, R.layout.scene_1, this)
        val scene2 = Scene.getSceneForLayout(scene_root, R.layout.scene_2, this)

        change_button.setOnCheckedChangeListener { buttonView, isChecked ->
            val transitionSet = TransitionSet().addTransition(ChangeBounds()).addTransition(ChangeScroll())
            if (isChecked) {
                TransitionManager.go(scene1,
                        TransitionSet()
                                .addTransition(ChangeTransform())
                                .addTransition(ChangeBounds())
                                .apply {
                                    duration = 2000
                                })
            } else {
                TransitionManager.go(scene2,
                        TransitionSet()
                        .addTransition(ChangeTransform())
                        .addTransition(ChangeBounds())
                        .apply {
                            duration = 2000
                        })
//                TransitionManager.go(scene2, TransitionInflater.from(this).inflateTransition(R.transition.slide_and_changebounds_sequential_with_interpolators))
            }

        }
    }
}
